<template>
  <div class="seach">
    <div class="seach_seach">
      <div class="seach_input">
        <input type="email" class="form-control" id="exampleFormControlInput1_1" v-model="userId" placeholder="请输入用户账号">
      </div>
      <div class="seach_input1">
        <input type="email" class="form-control" id="exampleFormControlInput1_1" v-model="userName" placeholder="请输入用户姓名">
      </div>
      <!-- <el-button class="input_buttons">默认按钮</el-button> -->
      <el-button size="small" class="input_buttons" type="primary" @click="user_seach">搜索</el-button>
    </div>
    <div class="seach_body">
      <!-- 开始 -->
      <el-table :data="this.users_Info" border stripe><!-- 带边框、斑马纹 -->
        <!-- <el-table-column type="index"></el-table-column> -->
        <el-table-column label="账号" prop="userId"></el-table-column>
        <el-table-column label="密码" prop="psWord"></el-table-column>
        <el-table-column label="姓名" prop="userName"></el-table-column>
        <el-table-column label="性别" prop="gender"></el-table-column>
        <el-table-column label="邮箱" prop="email"></el-table-column>
        <el-table-column label="电话" prop="phone"></el-table-column>
        <el-table-column label="身份" prop="ismaind" :formatter="change_ismains" ></el-table-column>
        <!-- <el-table-column label="身份" prop="ismaind"></el-table-column>  -->

        <el-table-column label="操作" width="200px">
            <template slot-scope="scope">
              <el-tooltip effect="dark" content="修改" placement="top">
                  <el-button type="primary" icon="el-icon-edit" size="mini"  @click="updata_data(scope.row)"></el-button>
                </el-tooltip>
                <el-tooltip effect="dark" content="删除" placement="top">
                  <el-button type="danger" icon="el-icon-delete" @click="updata_delete(scope.row)" size="mini"></el-button>
                </el-tooltip>
            </template>
        </el-table-column>
      <!-- </div> -->
      </el-table>
      <!-- 结束 -->
      <Notice v-if="this.notice" :tonote="this.tonote" :updata="this.getUsersList"></Notice>
      <Delete v-if="this.delete" :todelete="this.todelete"></Delete>
    </div>
    <div class="seach_bottom">
      <div class="bottom_buttons">
        <el-pagination
         background
         layout="prev, pager, next"
          @current-change="handleSizeChange"   
         @prev-click="handleCurrentChange"
         @next-click="handleCurrentChange"
         :total=this.gettotal>
        </el-pagination>
      </div>
      <!-- <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum" :page-sizes="[1, 2, 5, 10]" :page-size="queryInfo.pagesize" 
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination> -->
    </div>
  </div>
</template>
<script>
import Notice from '../components/user_notice.vue'
import Delete from '../components/Delete.vue'
import { log } from 'three';
export default({
  data(){
      return{
           deleteid:"",
           page:0,
           notice:false,
           delete:false, 
           gettotal:1, 
           userId:"",
           userName:"",
           ismaind:sessionStorage.getItem("ismaind"),
           users_Info:[
           ],
           tonote:{},
           test:[{userId:"20100140205",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:0},
           {userId:"20100140206",psWord:"123455",userName:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140207",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140206",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140207",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140206",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140207",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140206",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140207",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140206",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
           {userId:"20100140207",psWord:"123455",name:"kuangfeng",gender:"男",email:"123456@qq.com",phone:"12345678",ismaind:1},
        ]
      }
  },
  components:{
    Notice,
    Delete,
  },
  methods:{
    // 获取用户列表
    async getUsersList() {
      this.axios.get('http://192.168.43.171:8081/users/page', {
                      params:{
                       key: this.page,        
                      }
                   // 参数 name
                }).then( (response)=> {
                  this.gettotal=response.data.maxpage*10
                  // console.log(response);
                  this.users_Info=response.data.data;
                }).catch(function (error) {
                  console.log(error);
                });
    },
    // 修改是否为管理员
    change_ismains(row,column){
      if (row.ismaind==1) {
        return "管理员"
      } else {
        return "用户"
      }
    },
    // 当前页
    handleSizeChange(val) {
      // 
      this.page=val,
      this.user_seach()
      // this.axios.get('http://192.168.43.171:8081/users/page', {
      //                 params:{
      //                   key:val
      //                 }
      //              // 参数 name
      //           }).then( (response)=> {
      //             // if (response.data) {
      //             //     alert("登陆成功")
      //             //     // this.$router.push({ name: 'Index'})

      //             // } else {
      //             //     alert("登录失败")
      //             //     // this.account='',
      //             // }
      //             console.log(response.data.page);
      //             console.log(response);
      //             this.users_Info=response.data.page;
      //             console.log("1234567");
      //             console.log(this.users_Info);
      //           }).catch(function (error) {
      //             console.log(error);
      //           });
      // 
    },
    // 下一页或者上一页
    handleCurrentChange(val) {
      this.page=val,
      this.user_seach()
      // this.axios.get('http://192.168.43.171:8081/users/page', {
      //                 params:{
      //                   key:val
      //                 }
      //              // 参数 name
      //           }).then( (response)=> {
      //             // if (response.data) {
      //             //     alert("登陆成功")
      //             //     // this.$router.push({ name: 'Index'})

      //             // } else {
      //             //     alert("登录失败")
      //             //     // this.account='',
      //             // }
      //             console.log(response.data.page);
      //             console.log(response);
      //             this.users_Info=response.data.page;
      //             console.log("1234567");
      //             console.log(this.users_Info);
      //           }).catch(function (error) {
      //             console.log(error);
      //           });
    },
        // 给图书修改
    updata_data(row){
      this.notice=true;
      this.delete=false;
      this.tonote=row;
      console.log(this.tonote);
    },
    // 删除图书
    updata_delete(row){
      this.notice=false;
      this.delete=true;
      this.deleteid=row.userId
    },
    // 删除图书后被调用的delete调用函数
    todelete(){
      this.axios.get('http://192.168.43.171:8081/users/delete', {
                      params:{
                        userId:this.deleteid
                      }
                   // 参数 name
                }).then( (response)=> {
                  this.$message({
                 message: response.data.msg,
                  type: 'success'
                 });
                  this.getUsersList()
                }).catch(function (error) {
                  console.log(error);
                });
    },
    //seach
    user_seach(){
      this.axios.get('http://192.168.43.171:8081/users/page', {
                      params:{
                        key:this.page,
                        userId: this.userId,        // 参数 id
                        conditions:this.userName,
                      }
                   // 参数 name
                }).then( (response)=> {
                  this.gettotal=response.data.maxpage*10
                  console.log(response);
                  this.users_Info=response.data.data;
                }).catch(function (error) {
                  console.log(error);
                });
    }
  },
  mounted(){
    console.log(this.ismaind);
    console.log(1234567890);
        // 绑定事
        this.$bus.$on ('bus_delete_cancel', (data) => {
          this.delete=data;
          // console.log(data);
          if(data==1){
            this.delete=false
          }
        }),
        this.$bus.$on ('bus_delete', (data) => {
          // this.delete=data;
          console.log(data);
          if(data==1){
            this.delete=false
          }
        })
        this.$bus.$on ('bus_up_date_cancel', (data) => {
          // this.delete=data;
          if(data==1){
            this.notice=false
          }
        })
        this.$bus.$on ('bus_up_date', (data) => {
          // this.delete=data;
          if(data==1){
            this.notice=false
          }
        })
        this.getUsersList();
    },
    beforeDestroy(){
        // this.$bus.$off('bus_delete_cancel')
        this.$bus.$off('bus_delete')
        this.$bus.$off('bus_updata_cancel')
        this.$bus.$off('bus_updata')
        
      },
  beforeRouteEnter:(to,from,next)=>{
   const ismaind=sessionStorage.getItem("ismaind")
   console.log(ismaind);
    if (ismaind==1) {
      next()
    } else {
      alert("无权限")
    }
  }
})
</script>
<style lang="less" scoped>
.seach{
  width: 100%;
  height: 100%;
  position: absolute;
  .seach_seach{
    position: absolute;
    right: 50px;
    height: 6%;
    width: 70%;
    // background-color: #67c58b;
    .seach_input{
       position: absolute;
       width: 40%;
       top: 4px;
       left: 50;
    }
    .seach_input1{
       position: absolute;
       width: 40%;
       top: 4px;
       left: 358px;
    }
    .input_buttons{
     position: absolute;
     top: 16%;
     right: 11%;
    }
  }
  .seach_body{
  background-color: #fff;
  position: absolute;
  top: 7%;
  height: 80%;
  width: 100%;
  }

  .seach_bottom{
    // background-color: #5f9ca1;
    height: 10%;
    width: 100%;
    bottom: 1%;
    position: absolute;
    .bottom_buttons{
      position: absolute;
      top: 32%;
      height: 40%;
      width: 20%;
      left: 25%;
    }

  }
}

</style>